﻿function RedirectTo(obj, url) {
    $("a").removeClass("focus");
    $(obj).addClass("focus");
    top.frames["mainframe"].location = url;
}
function showMsg(msg) {
    $("#notification").fadeIn(4000);
    $("#notification").text(msg);
    $("#notification").fadeOut(4000);
}


function postFormJson(form) {
    $.post($("#" + form).attr("action"), $("#" + form).serialize(), function (json) {
        alert(form); if (json.err == 1) { alert(json.msg); }
    }, "json");
} // end postFormJson


function postFormJson(form,url) {
    $.post($("#" + form).attr("action"), $("#" + form).serialize(), function (json) {
        if (json.err == 1) { alert(json.msg); }
        else window.location.href = url;
    }, "json");
} // end postFormJson



//function checkAllItem() {
//    if ($('input:checkbox[name=chkcheckAll]').is(':checked') == true)
//        $('input:checkbox[name=chkid]').attr('checked', true);
//    else
//        $('input:checkbox[name=chkid]').attr('checked', false);

//    check();
//} //end checkall



function browserFile(element) {
    window.SetUrl = function (value) {
        element.value = value;
    }
    var filemanager = '/fckeditor/editor/filemanager/browser/default/browser.html';
    var connector = '../../connectors/aspx/connector.aspx';
    window.open(filemanager + '?Connector=' + connector, 'fileupload', 'modal,width=700,height=500');
} // END
function browserFileImageView(element, img_name) {
    window.SetUrl = function (value) {
        element.value = value;
        img_name.src = value;
    }

    var filemanager = '/fckeditor/editor/filemanager/browser/default/browser.html';
    var connector = '../../connectors/aspx/connector.aspx';
    window.open(filemanager + '?Connector=' + connector + "&Type=Image", 'fileupload', 'modal,width=700,height=500');
} // END
function browserFileType(element, type) {
    window.SetUrl = function (value) {
        element.value = value;
    }

    var filemanager = '/fckeditor/editor/filemanager/browser/default/browser.html';
    var connector = '../../connectors/aspx/connector.aspx';
    window.open(filemanager + '?Connector=' + connector + "&Type=" + type, 'fileupload', 'modal,width=700,height=500');
} // END
function browserFileImage(element) {
    window.SetUrl = function (value) {
        element.value = value;
    }

    var filemanager = '/fckeditor/editor/filemanager/browser/default/browser.html';
    var connector = '../../connectors/aspx/connector.aspx';
    window.open(filemanager + '?Connector=' + connector + "&Type=Image", 'fileupload', 'modal,width=700,height=500');
} // END

function browserFileFlash(element) {
    window.SetUrl = function (value) {
        element.value = value;
    }

    var filemanager = '/fckeditor/editor/filemanager/browser/default/browser.html';
    var connector = '../../connectors/aspx/connector.aspx';
    window.open(filemanager + '?Connector=' + connector + "&Type=Flash", 'fileupload', 'modal,width=700,height=500');
} // END
function browserFileMedia(element) {
    window.SetUrl = function (value) {
        element.value = value;
    }

    var filemanager = '/fckeditor/editor/filemanager/browser/default/browser.html';
    var connector = '../../connectors/aspx/connector.aspx';
    window.open(filemanager + '?Connector=' + connector + "&Type=Media" , 'fileupload', 'modal,width=700,height=500');
} // END


function locdau(obj) {
    var str;
    if (eval(obj))
        str = eval(obj).value;
    else
        str = obj;
    str = str.toLowerCase();
    str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, "a");
    str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e");
    str = str.replace(/ì|í|ị|ỉ|ĩ/g, "i");
    str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, "o");
    str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u");
    str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y");
    str = str.replace(/đ/g, "d");
    //str= str.replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'| |\"|\&|\#|\[|\]|~|$|_/g,"-");  
    /* tìm và thay thế các kí tự đặc biệt trong chuỗi sang kí tự - */
    //str= str.replace(/-+-/g,"-"); //thay thế 2- thành 1-  
    str = str.replace(/^\-+|\-+$/g, "");
    //cắt bỏ ký tự - ở đầu và cuối chuỗi 
    eval(obj).value = str.toUpperCase();
} // end locdau

// upload file images
function uploadimage(fileupload, onComplete) {
    $("#" + fileupload).uploadify({
        'uploader': '/Admin/Content/uploadify/uploadify.swf',
        'script': '/Handler/UploadHandler.ashx',
        'cancelImg': '/Admin/Content/uploadify/cancel.png',
        'buttonText': '', 'buttonImg': '/Admin/Content/uploadify/folder_image.png',
        'folder': '/Upload/',
        'fileDesc': 'File ảnh(*.jpg;*.jpeg;*.gif;*.png)',
        'sizeLimit': 2097152,
        'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
        height: 16, width: 16,
        'onComplete': function (event, queueID, fileObj, response, data) {
            onComplete(response);
            //$("#Banner").val(response);
            //$("#hdImage").append("<img height='90' src='" + response + "'/>");
        },
        'multi': false,
        'auto': true,
        'onError': function (a, b, c, d) {
            if (d.status == 404)
                alert("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>");
            else if (d.type === "HTTP")
                alert("error " + d.type + ": " + d.status);
            else if (d.type === "File Size")
                alert(c.name + " " + d.type + " Limit: " + Math.round(d.sizeLimit / 1024) + "KB");
            else
                alert("error " + d.type + ": " + d.text);
        }
    });
}
/// end up load file 


// upload file images
function uploadvideo(fileupload, onComplete) {
    $("#" + fileupload).uploadify({
        'uploader': '/Admin/Content/uploadify/uploadify.swf',
        'script': '/Handler/UploadHandler.ashx',
        'cancelImg': '/Admin/Content/uploadify/cancel.png',
        'buttonText': '', 'buttonImg': '/Admin/Content/uploadify/folder_image.png',
        'folder': '/Upload/',
        'fileDesc': 'File video(*.flv;*.avi;*.swf;*.wmv;*.mp4)',
        'sizeLimit': 104857600,
        'fileExt': '*.flv;*.avi;*.swf;*.wmv;*.mp4',
        height: 16, width: 16,
        'onComplete': function (event, queueID, fileObj, response, data) {
            onComplete(response); 
        },
        'multi': false,
        'auto': true,
        'onError': function (a, b, c, d) {
            if (d.status == 404)
                alert("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>");
            else if (d.type === "HTTP")
                alert("error " + d.type + ": " + d.status);
            else if (d.type === "File Size")
                alert(c.name + " " + d.type + " Limit: " + Math.round(d.sizeLimit / 1024) + "KB");
            else
                alert("error " + d.type + ": " + d.text);
        }
    });
}
/// end up load file 
// upload file images
function uploadradio(fileupload, onComplete) {
    $("#" + fileupload).uploadify({
        'uploader': '/Admin/Content/uploadify/uploadify.swf',
        'script': '/Handler/UploadHandler.ashx',
        'cancelImg': '/Admin/Content/uploadify/cancel.png',
        'buttonText': '', 'buttonImg': '/Admin/Content/uploadify/folder_image.png',
        'folder': '/Upload/',
        'fileDesc': 'File radio(*.mp3;*.wav;*.wma;*.asf;*.m4a)',
        'sizeLimit': 104857600,
        'fileExt': '*.mp3;*.wav;*.wma;*.asf;*.m4a',
        height: 16, width: 16,
        'onComplete': function (event, queueID, fileObj, response, data) {
            onComplete(response);
        },
        'multi': false,
        'auto': true,
        'onError': function (a, b, c, d) {
            if (d.status == 404)
                alert("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>");
            else if (d.type === "HTTP")
                alert("error " + d.type + ": " + d.status);
            else if (d.type === "File Size")
                alert(c.name + " " + d.type + " Limit: " + Math.round(d.sizeLimit / 1024) + "KB");
            else
                alert("error " + d.type + ": " + d.text);
        }
    });
}
/// end up load file 